﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.NetworkInformation;

namespace KtcAr.Services.Monitors
{
    public class PingMonitor : KtcAr.Services.Monitors.IMonitor
    {
        #region Attributes / Properties

        protected string host;

        #endregion

        #region Constructor
        private PingMonitor() { }
        public PingMonitor(string aHost)
        {
            this.host = aHost;
        }

        #endregion

        /// <summary>
        /// Validate if the specified host is alive sending an ICMP message
        /// </summary>
        /// <returns>True if it is Alive, False if not</returns>
        public bool IsAlive()
        {
            return this.DoPing() == IPStatus.Success;
        }

        private IPStatus DoPing()
        {
            return new Ping().Send(host).Status;
        }

        public virtual MonitorResult CheckIt()
        {
            MonitorResult result = new MonitorResult();
            result.PingStatus = this.DoPing();
            return result;
        }
    }
}
